package com.android.binderserverclient0.workmanager

import android.content.Context
import android.util.Log
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf

class ContinuationCheck5(context: Context, params: WorkerParameters) : Worker(context, params) {

    override fun doWork(): Result {
        val stringBuilder = StringBuilder()
        for ((key, value) in inputData.keyValueMap) {
            stringBuilder
                .append(key)
                .append(" : ")
            if (value is Array<*>) {
                stringBuilder.append("[")
                value.forEach {
                    stringBuilder
                        .append(it)
                        .append(",")
                }
                stringBuilder.also {
                    it.delete(it.lastIndexOf(",") - 1, it.length)
                }
                stringBuilder.append("]")
            } else {
                stringBuilder.append(value)
            }
            stringBuilder.append("\n")
        }
        Thread.sleep(3000)
        Log.d("ContinuationCheck", "ContinuationCheck5 $stringBuilder")
        return Result.success(workDataOf("whereFrom" to "This is from ContinuationCheck5"))
    }
}